import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import Layout from '@/Views/Layout/index.vue'
import NewsPool from '@/Views/NewsPool/index.vue'
import NewsPost from '@/Views/NewsPost/index.vue'
import System from '@/Views/System/index.vue'
import Log from '@/Views/Log/index.vue'
import Notification from '@/Views/Notification/index.vue'
import International from '@/Views/International/index.vue'
// import previewView from '@/Views/Preview/previewView.vue'
import previewDetail from '@/Views/Preview/previewDetail.vue'
import previewList from '@/Views/Preview/previewList.vue'

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        name: 'layout',
        component: Layout,
        children: [
            {
                path: 'pool',
                name: 'pool',
                component: NewsPool
            },
            {
                path: 'post',
                name: 'post',
                component: NewsPost
            },
            {
                path: 'published',
                name: 'published',
                component: () => import('@/Views/PublishedNews/index.vue')
            },
            {
                path: 'system',
                name: 'system',
                component: System
            },
            {
                path: 'log',
                name: 'log',
                component: Log
            },
            {
                path: 'notification',
                name: 'notification',
                component: Notification
            },
            {
                path: 'international',
                name: 'international',
                component: International
            },
        ]
    },

  {
  path: '/preview',
  name: 'preview',
  component: previewList,
  },
    {
      path: '/previewdetail',
      name: 'previewDetail',
      component: previewDetail
    },


    {
        path: '/login',
        name: 'login',
        component: () => import('@/Views/Login/index.vue')
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

router.beforeEach((to, from) => {
    const login = localStorage.getItem('login')
    if (to.name !== 'login' && !login) {
        return { name: 'login' }
    }
    return true
})

export default router